<template>
  <div class="app-container">
    <el-container>
      <el-header style="width: 100%;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
        <p style="float: left;margin: 0px 45px;font-size: 19px;">门诊挂号</p>
        <el-row v-show="showInvoice">
          <el-col :span="3">
            <el-input placeholder="发票号" v-model="invoiceNo" size="mini"/>
          </el-col>
          <el-col :span="2">
            <el-button size="mini" @click="updateReceiptNumber">更新发票号</el-button>
          </el-col>
        </el-row>
      </el-header>
      <el-row style="position: absolute;right: 60px;top: 32px;">
        <el-button type="text" icon="el-icon-thumb" @click="Registered" :disabled="registeredDisabled">挂号</el-button>
        <el-button type="text" icon="el-icon-upload" @click="CardReadelog" :disabled="cardReade">读卡</el-button>
        <el-button type="text" icon="el-icon-refresh-right">重打</el-button>
      </el-row>
      <el-main
        v-show="show"
        style="margin-top: 10px;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
        <el-row style="float: left;margin-left:70px;margin-bottom: 10px">
          <el-col :span="10">
            <el-button>挂号信息列表</el-button>
          </el-col>
          <el-col :span="12">
            <el-input placeholder="病历号/姓名" clearable v-model="queryParams.name"></el-input>
          </el-col>
          <el-col :span="2">
            <el-button icon="el-icon-search" @click="handleQuery"></el-button>
          </el-col>
        </el-row>
        <el-button size="mini" type="text" icon="el-icon-refresh" style="float: right;margin: 0px 80px;"
                   @click="loadRegistrationList">
          刷新
        </el-button>
        <!--        height: 300px;-->
        <el-table style="width: 100%;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)"
                  :header-cell-style="{color:'#333',background:'white',borderBottom:'1px solid black'}"
                  :data="registrationList" v-loading="loading">
          <el-table-column prop="date" label="操作" width="200" align="center">
            <template slot-scope="scope">
              <el-button
                size="small"
                plain
                v-if="scope.row.status===1"
                @click="openReturnNo(scope.row)"
              >退号
              </el-button>
              <el-button
                size="small"
                plain
                v-if="scope.row.status===1"
              >补打
              </el-button>
              <el-button
                size="small"
                plain
                @click="cost(scope.row,1)"
                v-if="scope.row.status===2"
              >缴费
              </el-button>
              <el-button
                size="small"
                plain
                @click="cost(scope.row,2)"
                v-if="scope.row.status===2"
              >退费
              </el-button>
              <el-button
                size="small"
                plain
                v-if="scope.row.status===4"
              >无
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="scope">
              <el-tag :type='statusColour[scope.row.status]'>{{registrationStatus[scope.row.status]}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="pmsPatient.medicalRecordNo" label="病历号" width="200" align="center"/>
          <el-table-column prop="pmsPatient.patientName" label="姓名" align="center"/>
          <el-table-column prop="pmsPatient.gender" label="性别" align="center" :formatter="genderFormat"/>
          <el-table-column prop="pmsPatient.dateOfBirth" label="出生日期" align="center"/>
          <el-table-column prop="attendanceDate" label="看诊日期" align="center"/>
          <el-table-column prop="sysDeptManager.deptName" label="看诊科目" align="center"/>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
        <!-- 退号弹框 -->
        <el-dialog :title="returnNoTitle" :visible.sync="returnNoOpen" width="500px" append-to-body>
          <el-form ref="returnNoForm" :model="returnNoForm" :rules="rules" label-width="100px">
            <el-form-item label="发票Id" v-show="false">
              <el-input v-model="returnNoForm.id"></el-input>
            </el-form-item>
            <el-form-item label="挂号Id" v-show="false">
              <el-input v-model="returnNoForm.registrationId"></el-input>
            </el-form-item>
            <el-form-item label="排班id" v-show="false">
              <el-input v-model="returnNoForm.skdId"></el-input>
            </el-form-item>
            <el-form-item label="发票号">
              <el-input v-model="returnNoForm.invoiceNo" placeholder="发票号"></el-input>
            </el-form-item>
            <el-form-item label="冲红发票号">
              <el-input v-model="returnNoForm.redInvoiceNo" placeholder="冲红发票号"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitReturnNoForm">确 定</el-button>
            <el-button @click="returnNoCancel">取 消</el-button>
          </div>
        </el-dialog>
      </el-main>

      <!--  挂号表单  -->
      <el-main v-show="shows" style="margin-top: 10px;height:400px;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
        <el-row style="margin-left: 100px">
          <el-form ref="registeredForm" :model="registeredForm" :rules="rulesRegistered"  :inline="true" >
            <el-col :span="8">
              <el-form-item label="身份证号" prop="identificationNo">
                <el-input v-model="registeredForm.identificationNo" placeholder="请输入身份证号"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="姓名" label-width="77px" prop="patientName">
                <el-input v-model="registeredForm.patientName" placeholder="请输入姓名"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="出生日期" prop="dateOfBirth">
                <div class="block">
                  <el-date-picker
                    type="date"
                    v-model="registeredForm.dateOfBirth"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="性别" label-width="77px" prop="gender">
                <el-select v-model="registeredForm.gender" placeholder="请选择">
                  <el-option
                    v-for="item in genderOption"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="家庭住址" prop="homeAddress">
                <el-input v-model="registeredForm.homeAddress" placeholder="请输入家庭住址"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系方式" prop="phoneNo">
                <el-input v-model="registeredForm.phoneNo" placeholder="请输入联系方式"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="挂号科室" prop="deptId">
                <el-select v-model="registeredForm.deptId" @change="registeredDept" clearable placeholder="请选择">
                  <el-option
                    v-for="item in deptList"
                    :key="item.deptId"
                    :label="item.deptName"
                    :value="item.deptId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="挂号级别" prop="registrationRankId">
                <el-select v-model="registeredForm.registrationRankId" @change="registeredLevel" placeholder="请选择">
                  <el-option
                    v-for="r in registrationRankList"
                    :key="r.id"
                    :label="r.name"
                    :value="r.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="挂号日期" prop="date">
                <div class="block">
                  <el-date-picker
                    @change="registeredChange"
                    v-model="registeredForm.date"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="date"
                    placeholder="选择日期"
                    default-time="12:00:00">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="午别" label-width="77px" prop="noon">
                <el-select v-model="registeredForm.noon" :disabled="noonDisabled" @change="noonChange"
                           placeholder="请选择">
                  <el-option
                    v-for="n in noonOption"
                    :label="n.dictLabel"
                    :value="n.dictValue">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="看诊医生" prop="userName">
                <el-select v-model="registeredForm.userName" :disabled="userNameDisabled" clearable placeholder="请选择">
                  <el-option
                    v-for="s in seeDoctorList"
                    :label="s.userName"
                    :value="s.userId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="应收金额" label-width="77px">
                <el-input disabled v-model="registeredForm.price"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="支付方式" prop="settlement">
                <el-select v-model="registeredForm.settlement" clearable placeholder="请选择">
                  <el-option
                    v-for="t in settlementTypeList"
                    :label="t.name"
                    :value="t.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="病历本" label-width="77px" prop="needBook">
                <el-radio-group v-model="registeredForm.needBook">
                  <el-radio
                    v-for="o in needOption"
                    :value="o.dictLabel"
                    :label="o.dictValue"
                  >{{o.dictLabel}}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-button type="primary" style="float: right;margin-top: 60px" @click="saveAndPrit">挂号&打印发票</el-button>
          </el-form>
        </el-row>
      </el-main>

      <!--缴费退费-->
      <el-main v-show="showPayment"
               style="margin-top: 10px;height:600px;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
        <el-row>
          <el-form ref="costForm" :inline="true" :model="formCostInfo" :rules="rulesCost">
            <el-col :span="6" style="margin-left: 150px;">
              <el-form-item label="病历号" label-width="70px">
                <el-input disabled v-model="formCostInfo.medicalRecordNo"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="患者姓名" label-width="70px">
                <el-input disabled v-model="formCostInfo.name"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="看诊日期">
                <el-input disabled v-model="formCostInfo.attendanceDate"/>
              </el-form-item>
            </el-col>
            <el-table :data="costList" @selection-change="handleSelectionChange"
              :header-cell-style="{color:'#333',background:'white',borderBottom:'1px solid black'}">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column label="项目名称" align="center" prop="name"/>
              <el-table-column label="总金额(元)" align="center" prop="amount"/>
              <el-table-column label="开立时间" align="center" prop="createTime"/>
              <el-table-column label="项目类型" align="center" prop="type">
                <template scope="scope">
                  <el-tag v-if="scope.row.type == 1">检查</el-tag>
                  <el-tag v-if="scope.row.type == 2">检验</el-tag>
                  <el-tag v-if="scope.row.type == 3">处置</el-tag>
                  <el-tag v-if="scope.row.type == 4">成药处方</el-tag>
                  <el-tag v-if="scope.row.type == 5">草药处方</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="状态" align="center" prop="status">
                <template scope="scope">
                  <el-tag v-if="scope.row.status == 1">未缴费</el-tag>
                  <el-tag type="success" v-if="scope.row.status == 2">可退费</el-tag>
                </template>
              </el-table-column>
            </el-table>
            <el-row style="margin-left: 560px;margin-top: 20px">
              <el-col :span="3">
                <el-form-item label="应付：">
<!--                  <el-tag v-text="formCostInfo.money">0</el-tag>-->
                  <el-input v-model="formCostInfo.amount" placeholder="0" disabled style=""></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="settlementCatId">
                  <el-select v-model="formCostInfo.settlementCatId" clearable placeholder="请选择支付类型">
                    <el-option
                      v-for="item in settlementTypeList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin-left: 620px">
              <el-col :span="10">
                <el-button type="primary" @click="submitFormCost" :disabled="multiple">确 定</el-button>
                <el-button @click="cancelCost">取 消</el-button>
              </el-col>
            </el-row>
          </el-form>
        </el-row>
      </el-main>

      <!--  读卡身份证弹框  -->
      <el-dialog :title="title" :visible.sync="open" width="400px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="身份证号" prop="identNo">
            <el-input v-model="form.identNo" placeholder="身份证号" clearable></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </el-container>
  </div>
</template>

<script>
  import {getPatientByIdent,addPatient} from "@/api/pms/patient";
  import {listSettlement_cat} from "@/api/bms/settlement_cat";
  import {listDept} from "@/api/sms/dept"
  import {listRegistration_rank, getRegistration_rank} from "@/api/sms/registration_rank";
  import {listSkdTerm} from "@/api/sms/skd";
  import {registrationPatientList, returnNo,addRegistration} from "@/api/dms/registration";
  import {getInvoiceNoByRegistrationId} from "@/api/bms/invoice_record";

  import {getListNon_drug_item_record } from "@/api/dms/non_drug_item_record";
  import {getListMedicine_prescription_record } from "@/api/dms/medicine_prescription_record";
  import {getListHerbal_prescription_record } from "@/api/dms/herbal_prescription_record";

  import { addInvoice_record, } from "@/api/bms/invoice_record"

  export default {
    name: "registration",
    data() {
      return {
        show: true,  //挂号信息列表显隐
        shows: false,  //挂号表单显隐
        showInvoice: false,  //发票号显隐
        showPayment: false,  //缴退费显隐
        //门诊挂号收费列表查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: undefined,
          medicalRecordNo: undefined
        },
        //门诊挂号收费列表总条数
        total: 0,
        //门诊挂号收费列表加载
        loading: true,
        //门诊挂号收费列表集合
        registrationList: [],
        //状态按钮颜色
        statusColour: {"1": "warning", "2": "danger", "3": "success", "4": "info"},
        //状态按钮值
        registrationStatus: {"1": "待诊", "2": "就诊中", "3": "诊毕", "4": "已退号"},
        // 性别字典
        genderOption: [],
        //退号弹框标题
        returnNoTitle: null,
        //退号弹框
        returnNoOpen: false,
        //退号表单
        returnNoForm: {},
        //支付方式
        settlementTypeList: [],
        payment: null,
        //挂号科室
        deptList: [],
        //挂号级别
        registrationRankList: [],
        //看诊医生
        seeDoctorList: [],
        showPayment: false,  //缴退费显隐
        //读卡禁用
        cardReade: true,
        //弹框
        open: false,
        //标题
        title: null,
        //就诊医生禁用
        userNameDisabled: true,
        //午别禁用
        noonDisabled: true,
        //午别字典
        noonOption: [],
        //病历本字典
        needOption: [],
        //发票号
        invoiceNo:null,
        //身份证表单
        form: {},
        //挂号表单
        registeredForm: {},
        //身份证表单验证
        rules: {
          identNo: [
            {required: true, message: "身份证不能为空"},
            {
              pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
              message: '请输入合法身份证号'
            }
          ]
        },
        //挂号表单验证
        rulesRegistered: {
          identificationNo: [
            {required: true, message: "身份证不能为空", trigger: 'blur'},
            {
              pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
              message: '请输入合法身份证号'
            }
          ],
          patientName: [
            {required: true, message: "姓名不能为空", trigger: 'blur'}
          ],
          dateOfBirth: [{
            required: true, message: "出生日期不能为空", trigger: 'blur'
          }],
          gender: [{
            required: true, message: "性别不能为空", trigger: 'blur'
          }],
          homeAddress: [{
            required: true, message: "家庭地址不能为空", trigger: 'blur'
          }],
          phoneNo: [{
            required: true, message: "联系方式不能为空", trigger: 'blur'
          }],
          deptId: [{
            required: true, message: "请选择挂号科室", trigger: 'blur'
          }],
          registrationRankId: [{
            required: true, message: "请选择挂号级别", trigger: 'blur'
          }],
          date: [{
            required: true, message: "请选择挂号日期", trigger: 'blur'
          }],
          noon: [{
            required: true, message: "请选择午别", trigger: 'blur'
          }],
          userName: [{
            required: true, message: "请选择看诊医生", trigger: 'blur'
          }],
          settlement: [{
            required: true, message: "请选择支付方式", trigger: 'blur'
          }],
          needBook: [{
            required: true, message: "请选择午别", trigger: 'blur'
          }]
        },
        //挂号是否禁用
        registeredDisabled:false,
        //缴费|退费 病人信息
        formCostInfo:{},
        //缴费|退费信息集合
        costList:[],
        // 非多个禁用
        multiple: true,
        //表单验证
        rulesCost: {
          settlementCatId: [{
            required: true, message: "请选择支付类型", trigger: 'blur'
          }]
        },
        //缴费|退费选中集合
        recordList: [],

      };
    },
    created() {
      this.getList();
      this.loadRegistration();
      this.generateInvoiceNumber();
      //性别字典数据
      this.getDicts("sys_user_sex").then(response => {
        this.genderOption = response.data;
      });
      //午别字典数据
      this.getDicts("sms_skd_noon").then(response => {
        this.noonOption = response.data;
      });
      //病历本字典
      this.getDicts("need_book").then(response => {
        this.needOption = response.data;
      });
    },
    methods: {
      /**根据患者姓名或病历号搜索*/
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 查询门诊挂号信息列表 */
      getList() {
        this.loading = true;
        registrationPatientList(this.queryParams).then(response => {
          this.registrationList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 刷新门诊挂号列表 */
      loadRegistrationList() {
        this.getList();
      },
      /** 加载门诊挂号信息 */
      loadRegistration() {
        //支付类型
        listSettlement_cat().then(response => {
          this.settlementTypeList = response.rows;
        });
        //挂号科室分类
        listDept().then(response => {
          this.deptList = response.rows;
        });
        //挂号级别
        listRegistration_rank().then(response => {
          this.registrationRankList = response.rows;
        });
      },
      /** 挂号科室改变事件 */
      registeredDept() {
        this.getDocker()
      },
      /** 挂号级别改变事件 */
      registeredLevel() {
        //获取挂号级别ID
        var rank_Id = this.registeredForm.registrationRankId;
        //查询对应级别的金额
        getRegistration_rank(rank_Id).then(response => {
          this.registeredForm.price = response.data.price;
        });
        this.getDocker();
      },
      /** 挂号日期改变事件 */
      registeredChange() {
        this.noonDisabled = false;
        this.userNameDisabled = false;
        this.getDocker()
      },
      /** 午别改变事件 */
      noonChange() {
        this.getDocker();
      },
      /** 查询已排班医生 */
      getDocker() {
        listSkdTerm(this.registeredForm).then(response => {
          if (response.data == '') {
            this.registeredForm.userName = null;
          }
          this.seeDoctorList = response.data;
          this.seeDoctorList.map(item => {
            this.registeredForm.skdId = item.id;
          })
        });
      },
      /** 挂号弹框 */
      Registered() {
        this.show = !this.show;
        this.shows = !this.shows;
        this.showInvoice = !this.showInvoice;
        this.cardReade = !this.cardReade;
        this.generateInvoiceNumber();
      },
      /** 读卡弹框 */
      CardReadelog() {
        this.title = '读卡(获取用户身份证号)';
        this.open = true;
        // this.$refs['form'].clearValidate(['identNo']);
      },
      /** 读卡取消 */
      cancel() {
        this.open = false;
        this.form = {}
      },
      /** 读卡提交 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            //获取身份证号
            var identNo = this.form.identNo;
            //根据身份证获取病人基本信息
            getPatientByIdent(identNo).then(response => {
              //表单赋值
              this.registeredForm = response.data;
              this.registeredForm.patientId = response.data.id;
              this.registeredForm.gender = this.registeredForm.gender + "";
              this.msgSuccess("读取身份证信息成功")
            });
            //关闭身份证弹框
            this.form = {};
            this.open = false;
          }
        })
      },
      /** 性别字典翻译*/
      genderFormat(row, column) {
        return this.selectDictLabel(this.genderOption, row.pmsPatient.gender);
      },
      /** 退号表单重置*/
      returnNoReset() {
        this.returnNoForm = {
          //就诊id
          registrationId: null,
          //冲红发票编号
          redInvoiceNo: null,
          //发票编号
          invoiceNo: null,
          //科室id
          skdId: null,
          // 发票id
          id: null
        };
        this.resetForm("returnNoForm");
      },
      /**打开退号弹框*/
      openReturnNo(data) {
        this.returnNoReset();
        this.returnNoOpen = true;
        this.returnNoTitle = "退号";
        this.returnNoForm.skdId = data.skdId;
        this.returnNoForm.registrationId = data.id;
        getInvoiceNoByRegistrationId(data.id).then(response => {
          this.returnNoForm.redInvoiceNo = response.data.invoiceNo;
          this.returnNoForm.invoiceNo = response.data.invoiceNo;
          this.returnNoForm.id = response.data.id;
        })
      },
      /**退号表单提交*/
      submitReturnNoForm() {
        this.$refs["returnNoForm"].validate(valid => {
          if (valid) {
            returnNo(this.returnNoForm).then(response => {
              if (response.code === 200) {
                this.msgSuccess("退号成功");
                // 弹窗关闭
                this.returnNoCancel();
                // 刷新列表
                this.getList();
              }
            });
          }
        })
      },
      /**退号表单取消*/
      returnNoCancel() {
        this.returnNoOpen = false;
      },
      /** 生成发票号*/
      generateInvoiceNumber() {
        var testDate = new Date();
        var num = "";
        for (let i = 1; i <= 4; i++) {
          num += parseInt(Math.random() * 10) + '';
        }
        var year = testDate.getFullYear() + '';
        var month = testDate.getMonth() + 1 + '';
        var date = testDate.getDate();
        this.invoiceNo = year + '0' + month + '0' + date + num;
      },
      /** 更新发票号*/
      updateReceiptNumber() {
        this.generateInvoiceNumber();
      },
      /** 计算年龄*/
      calculateAge() {
        let birthdays = new Date(this.registeredForm.dateOfBirth);
        let date = new Date();
        let age = date.getFullYear() - birthdays.getFullYear() -
          (date.getMonth() < birthdays.getMonth() || (date.getMonth() == birthdays.getMonth() && date.getDate() < birthdays.getDate()) ? 1 : 0);
        return age + "岁";
      },
      /**挂号&打印发票*/
      saveAndPrit() {
        /* 未做: 身份证唯一 待重名验证 表单还未清空 */
        this.$refs["registeredForm"].validate(valid => {
          if (valid) {
            this.registeredForm.attendanceDate = this.registeredForm.date;
            this.registeredForm.invoiceNo = this.invoiceNo;
            this.registeredForm.patientAgeStr = this.calculateAge();
            if (this.registeredForm.id != null) {
              //新增
              addRegistration(this.registeredForm);
              this.getList();
            } else {
              addPatient(this.registeredForm).then(response => {
                this.registeredForm.patientId = response.data;
                addRegistration(this.registeredForm);
                this.getList();
              });
            }
            this.msgSuccess("挂号成功");
            this.Registered();
          }
        });
      },
      /** 缴费 | 退费*/
      cost(row, status) {
        this.formCostInfo = {};
        this.costList = [];
        this.show = false;
        this.generateInvoiceNumber();
        this.showPayment = true;
        this.showInvoice = !this.showInvoice;
        this.registeredDisabled = !this.registeredDisabled;
        this.formCostInfo.registrationId = row.id;
        this.formCostInfo.status = status;
        /** 检查检验处置数据*/
        getListNon_drug_item_record(this.formCostInfo).then(response => {
          this.costList = this.costList.concat(response.data);
        });
        /** 成药数据*/
        getListMedicine_prescription_record(this.formCostInfo).then(response => {
          this.costList = this.costList.concat(response.data);
        });
        /** 草药数据*/
        getListHerbal_prescription_record(this.formCostInfo).then(response => {
          this.costList = this.costList.concat(response.data);
        });
        /** 病人信息 */
        this.formCostInfo.medicalRecordNo = row.pmsPatient.medicalRecordNo;
        this.formCostInfo.name = row.pmsPatient.patientName;
        this.formCostInfo.attendanceDate = row.attendanceDate;
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.recordList = selection.map(item => item);
        this.amount = selection.map(item => item.amount);
        this.formCostInfo.amount = 0;
        for (let i = 0; i < this.amount.length; i++){
          this.formCostInfo.amount += this.amount[i];
        }
        this.multiple = !selection.length;
      },
      /** 缴费 | 退费 确定按钮事件 */
      submitFormCost() {
        this.$refs["costForm"].validate(valid => {
          if (valid) {
            this.formCostInfo.invoiceNo = this.invoiceNo;
            this.formCostInfo.bmsRecordListVos = this.recordList;
            addInvoice_record(this.formCostInfo).then(response => {
              if(response.code == 200){
                this.msgSuccess("缴费成功");
                this.show = true;
                this.showPayment = false;
                this.showInvoice = !this.showInvoice;
                this.registeredDisabled = !this.registeredDisabled;
              }
            });
          }
        });
      },
      /** 缴费 | 退费 取消按钮事件 */
      cancelCost() {
        this.show = true;
        this.showPayment = false;
        this.showInvoice = !this.showInvoice;
        this.registeredDisabled = !this.registeredDisabled;
        this.$refs["costForm"].clearValidate();
      },
    }
  }
</script>

<style scoped>
  .el-header {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
</style>

